package com.library.servlet;

import com.library.bean.User;
import com.library.service.UserService;
import com.library.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UserLoadServlet", value = "/UserLoadServlet")
public class UserLoadServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");
        UserService userService=new UserServiceImpl();
        User newUser=new User(userName,password);
        User user=userService.userLoad(newUser);

        if(user.getUserName().equals(userName)&&user.getPassword().equals(password)){
            request.getRequestDispatcher("BookServlet").forward(request, response);;
        }else{
            request.getRequestDispatcher("login.jsp").forward(request, response);;
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
